Summary of Pearl 2014
Indirect effect: is a*c
Direct effect: b
Total effect: b + a*c - a
library(dplyr)
group = rep(c('B', 'A'), e=5)
pre = c(20,10,60,20,10,50,10,40,20,10)
post = c(70,50,90,60,50,20,10,30,50,10)
df = data.frame(id=factor(1:10), group, pre, post)
change = post-pre
dflong = tidyr::gather(df, key=time, value=score, pre:post) %>% arrange(id)
head(df)
id group pre post
1 1 B 20 70
2 2 B 10 50
3 3 B 60 90
4 4 B 20 60
5 5 B 10 50
6 6 A 50 20
head(dflong)
id group time score
1 1 B pre 20
2 1 B post 70
3 2 B pre 10
4 2 B post 50
5 3 B pre 60
6 3 B post 90
It’s an extremely large group difference.
mod = "
pre ~ a*group
post ~ b*group + c*pre
# change ~ -1*pre + 1*post
# total effect
TE := (b + a*c) - a
"
library(lavaan)
lpmod = sem(mod, data=df)
summary(lpmod)
lavaan (0.5-20) converged normally after 40 iterations
Number of observations 10
Estimator ML
Minimum Function Test Statistic 0.000
Degrees of freedom 0
Parameter Estimates:
Information Expected
Standard Errors Standard
Regressions:
Estimate Std.Err Z-value P(>|z|)
pre ~
group (a) -2.000 11.027 -0.181 0.856
post ~
group (b) 41.053 7.490 5.481 0.000
pre (c) 0.526 0.214 2.454 0.014
Variances:
Estimate Std.Err Z-value P(>|z|)
pre 304.000 135.953 2.236 0.025
post 139.789 62.516 2.236 0.025
Defined Parameters:
Estimate Std.Err Z-value P(>|z|)
TE 42.000 9.121 4.605 0.000
summary(lm(change~group, df)) # t-test on change scores = total effect
Call:
lm(formula = change ~ group, data = df)
Residuals:
Min 1Q Median 3Q Max
-28 -6 0 2 32
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -2.000 7.211 -0.277 0.78854
groupB 42.000 10.198 4.118 0.00335 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 16.12 on 8 degrees of freedom
Multiple R-squared: 0.6795, Adjusted R-squared: 0.6394
F-statistic: 16.96 on 1 and 8 DF, p-value: 0.003351
summary(lm(post~group+pre, df)) # 'ancova' uncovers direct effect etc.
Call:
lm(formula = post ~ group + pre, data = df)
Residuals:
Min 1Q Median 3Q Max
-16.632 -6.368 -3.737 4.947 29.158
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 10.3158 9.1840 1.123 0.29838
groupB 41.0526 8.9522 4.586 0.00253 **
pre 0.5263 0.2563 2.054 0.07912 .
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 14.13 on 7 degrees of freedom
Multiple R-squared: 0.776, Adjusted R-squared: 0.712
F-statistic: 12.12 on 2 and 7 DF, p-value: 0.005321
- low birthweight children have higher mortality rate (100 fold higher)
- children of smoking mothers notably more likely to have low birghtweight
- low birthweight children born to smoking mothers have a lower mortality rate
- Conclusion: expectant mothers should start smoking!